package com.ygf.config;

import com.ygf.service.CarService2;
import com.ygf.service.UserAService;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.stereotype.Component;

/**
 * <p>
 * description:
 * </p>
 *
 * @author yangguanfeng
 * @since 2021/4/26 11:25
 */
//@Component
public class TestABeanDefinitionRegistryPostProcessor implements BeanDefinitionRegistryPostProcessor {
	@Override
	public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
		System.out.println("-------扩展BeanDefinitionRegistryPostProcessor ，注册一个bean-------");
		BeanDefinition bd = new GenericBeanDefinition();
		bd.setBeanClassName(UserAService.class.getName());
		registry.registerBeanDefinition("userAService", bd);
	}

	@Override
	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

		System.out.println("-------扩展BeanDefinitionRegistryPostProcessor ，修改bean-------");

		BeanDefinition carService = beanFactory.getBeanDefinition("carService");
		carService.setBeanClassName(CarService2.class.getName());
	}
}
